package cn.oesoft.tennissystem.dao;

import java.util.List;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import cn.oesoft.tennissystem.model.entity.TennisRacket;
import cn.oesoft.tennissystem.model.entity.Statistic;
/**
 * @Classname StatisticMapper
 * @Description TODO
 * @Date 2020-7-19 23:18
 * @Created by linxin
 */

@Mapper
public interface StatisticMapper {
    // 新增网球拍对应的统计信息
    @Insert("INSERT INTO t_statistic(tennis_racket_id,hits,comments_num) values (#{id},0,0)")
    public void addStatistic(TennisRacket tennis_racket);

    // 根据网球拍id查询点击量和评论量相关信息
    @Select("SELECT * FROM t_statistic WHERE tennis_racket_id=#{tennisRacketId}")
    public Statistic getByTennisRacketId(Integer tennisRacketId);

    // 通过网球拍id更新点击量
    @Update("UPDATE t_statistic SET hits=#{hits} " +
            "WHERE tennis_racket_id=#{tennisRacketId}")
    public void updateHitsByTennisRacketId(Statistic statistic);

    // 通过网球拍id更新评论量
    @Update("UPDATE t_statistic SET comments_num=#{commentsNum} " +
            "WHERE tennis_racket_id=#{tennisRacketId}")
    public void updateCommentsNumByTennisRacketId(Statistic statistic);

    // 根据网球拍id删除统计数据
    @Delete("DELETE FROM t_statistic WHERE tennis_racket_id=#{tennisRacketId}")
    public void deleteByTennisRacketId(int tennisRacketId);

    // 统计网球拍热度信息
    @Select("SELECT * FROM t_statistic WHERE hits !='0' " +
            "ORDER BY hits DESC, comments_num DESC")
    public List<Statistic> getStatistic();

    // 统计所有网球拍总访问量
    @Select("SELECT SUM(hits) FROM t_statistic")
    public long getTotalVisit();

    // 统计所有网球拍总评论量
    @Select("SELECT SUM(comments_num) FROM t_statistic")
    public long getTotalComment();
}

